/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.core.dao;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.tech15.core.model.*;
import com.tech15.core.dao.*;
import com.tech15.core.service.*;
import com.tech15.core.vo.query.*;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


import static cn.org.rapid_framework.util.ObjectUtils.*;
import org.springframework.stereotype.Repository;

@Repository
public class SysModuleDataDao extends BaseHibernateDao<SysModuleData,Long>{

	public Class getEntityClass() {
		return SysModuleData.class;
	}
	
	public Page findByPageRequest(PageRequest<Map> pageRequest) {
		//XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
		// [column]为字符串拼接, {column}为使用占位符. 以下为图方便采用sql拼接,适用性能要求不高的应用,使用占位符方式可以优化性能. 
		// [column] 为PageRequest.getFilters()中的key
		String sql = "select t from SysModuleData t where 1=1 "
				+ "/~ and t.name = '[name]' ~/"
				+ "/~ and t.mdno = '[mdno]' ~/"
				+ "/~ and t.remark = '[remark]' ~/"
				+ "/~ and t.pid = '[pid]' ~/"
				+ "/~ and t.url = '[url]' ~/"
				+ "/~ and t.sortno = '[sortno]' ~/"
				+ "/~ and t.isshfw = '[isshfw]' ~/"
				+ "/~ order by [sortColumns] ~/";
		return pageQuery(sql,pageRequest);
	}
	
	public Page findPage(SysModuleDataQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
		String sql = "select t from SysModuleData t where 1=1 "
			  	+ "/~ and t.name = {name} ~/"
			  	+ "/~ and t.mdno = {mdno} ~/"
			  	+ "/~ and t.remark = {remark} ~/"
			  	+ "/~ and t.pid = {pid} ~/"
			  	+ "/~ and t.url = {url} ~/"
			  	+ "/~ and t.sortno = {sortno} ~/"
			  	+ "/~ and t.isshfw = {isshfw} ~/"
				+ "/~ order by [sortColumns] ~/";
				
        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
        StringBuilder sql2 = new StringBuilder("select t from SysModuleData t where 1=1 ");
        if(isNotEmpty(query.getMdid())) {
            sql2.append(" and  t.mdid = :mdid ");
        }
        if(isNotEmpty(query.getName())) {
            sql2.append(" and  t.name = :name ");
        }
        if(isNotEmpty(query.getMdno())) {
            sql2.append(" and  t.mdno = :mdno ");
        }
        if(isNotEmpty(query.getRemark())) {
            sql2.append(" and  t.remark = :remark ");
        }
        if(isNotEmpty(query.getPid())) {
            sql2.append(" and  t.pid = :pid ");
        }
        if(isNotEmpty(query.getUrl())) {
            sql2.append(" and  t.url = :url ");
        }
        if(isNotEmpty(query.getSortno())) {
            sql2.append(" and  t.sortno = :sortno ");
        }
        if(isNotEmpty(query.getIsshfw())) {
            sql2.append(" and  t.isshfw = :isshfw ");
        }
        if(isNotEmpty(query.getSortColumns())) {
            sql2.append(" order by :sortColumns ");
        }	
        
		return pageQuery(sql,query);
	}
	

}
